﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using bdtheque.data.poco;
using System.Web;
using System.Data.Entity;
using bdtheque.data.enums;

namespace bdtheque.business.bo
{
    // Implementation of the Facade Pattern to encapsulate access to some of the Session Variables
    public static class SessionFacade
    {
        private const string authenticatedUserId = "AuthenticatedUserId";
        private const string authenticatedUserIsActive = "AuthenticatedUserIsActive";
        private const string authenticatedUserRole = "AuthenticatedUserRole";

        public static int? UserId
        {
            get 
            { 
                if(HttpContext.Current.Session[authenticatedUserId] == null)
                    return null;
                else
                    return int.Parse(HttpContext.Current.Session[authenticatedUserId].ToString()); 
            }

            set { HttpContext.Current.Session[authenticatedUserId] = value; }
        }

        public static bool UserIsActive
        {
            get { return bool.Parse(HttpContext.Current.Session[authenticatedUserIsActive].ToString()); }
            set { HttpContext.Current.Session[authenticatedUserIsActive] = value; }
        }

        public static UserRole UserRole
        {
            get 
            {                
                if (HttpContext.Current.Session[authenticatedUserRole] == null)
                    return UserRole.User;
                else
                    return (UserRole)HttpContext.Current.Session[authenticatedUserRole];
            }
            set { HttpContext.Current.Session[authenticatedUserRole] = value; }
        }
    }
}
